from pynput.mouse import Button, Controller
import tkinter
import random
import 手势动作模块_动作判断_双手模式_握拳版 as motion
from pynput import keyboard

mouse = Controller()
keyboard = keyboard.Controller()

motion = motion.MotionDetection()


class HandAction():
    def __init__(self):
        pass


    # 分配左右手
    def action(self, type, lmList):
        if type == "Left":
            self.left(lmList)
        else:
            self.right(lmList)

    # 右手操作
    def right(self, lmList):
        if len(lmList) == 0:
            return

        # 握拳
        if motion.makeAFist(lmList):
            print("握拳")
            self.releaseAllKey()
        elif motion.indexFinger(lmList):
            print("右转(右食指)")
            pyautogui.press('right')
        elif motion.middleFingerAndIndexFinger(lmList):
            print("右漂移(shift)(中食指)")
            shift = pyautogui.keyDown('shift')
            print(shift)
            pyautogui.keyDown('right')
        else:
            # 左右手共同操作
            self.coOperation(lmList)

    # 左手操作
    def left(self, lmList):
        if motion.makeAFist(lmList):
            print("握拳")
            self.releaseAllKey()
        elif motion.indexFinger(lmList):
            pyautogui.press('left')
            print("左转(左食指)")
        elif motion.middleFingerAndIndexFinger(lmList):
            print("左漂移(shift)(中食指)")
            shift = pyautogui.keyDown('shift')
            print(shift)
            pyautogui.keyDown('left')
        else:
            # 左右手共同操作
            self.coOperation(lmList)

    # 释放全部按键
    def releaseAllKey(self):
        pyautogui.keyUp('shift')
        pyautogui.keyUp('left')
        pyautogui.keyUp('right')

    # 共同操作
    def coOperation(self, lmList):
        if motion.littleFinger(lmList):
            print("氮气加速(ctrl)(小拇指)")
            pyautogui.press('ctrl')
        elif motion.middleFinger(lmList):
            print("上方向键(小喷)(中指)")
            pyautogui.press('up')
        elif motion.ringFinger(lmList):
            print("R(复原)(无名指)")
            pyautogui.press('R')
        else:
            print("不做事情")
